package br.com.beiramar.action.rateio;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Out;

import br.com.beiramar.action.rateio.GerarRelatorioCorretoresNovosAction;

public class AgendadorTarefas implements Serializable{
	@In(create=true, required=false)
	@Out(required=false, scope=ScopeType.CONVERSATION)
	private GerarRelatorioCorretoresNovosAction ralat;
	
	private Timer timer;
	
	public void iniciar() {
        System.out.println("*********************** Chamou o agendador");
		timer = new Timer();
        //Executa tarefa a cada 24 horas a partir da primeira
        //       timer.schedule(new tarefasDiarias(),
        //        0,
        //        1 * 1000 * 60 * 60 * 24);
        //Executa tarefa todo dia as 6 da manha
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
        calendar.set(Calendar.HOUR_OF_DAY, 15);
        calendar.set(Calendar.MINUTE, 45);
        calendar.set(Calendar.SECOND, 0);
        Date time = calendar.getTime();
        timer.schedule(new tarefasDiarias(), time);
    }






class tarefasDiarias extends TimerTask implements Serializable {
	        public void run() {
	        	GerarRelatorioCorretoresNovosAction ger = new GerarRelatorioCorretoresNovosAction();
	        	
					try {
						ger.gerarRelatorioCorretoresNovos2();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				
					// TODO Auto-generated catch block
					
				
        }
    }
}
